package com.starblink.store.recommend.adapter

import android.app.Activity
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.aroute.CommonRoute
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.sensorsdata.extension.businessSuffixId
import com.starblink.android.basic.sensorsdata.extension.trackData
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmElementDef
import com.starblink.android.basic.sensorsdata.spm.impl.SpmTrackHandler
import com.starblink.basic.ext.load
import com.starblink.rocketreserver.fragment.ProductF
import com.starblink.store.databinding.ItemRecommendProductBinding

class RecommendStoreProductHolder(
    binding: ItemRecommendProductBinding,
    val context: Activity,
    val itemW: Int,
    val pageRef: Int,
    val merchantName: String?,
    val pageTrackTag: String = "",//
) :
    BaseBindingVH<ProductF, ItemRecommendProductBinding>(binding = binding) {

    override fun onBind(product: ProductF, position: Int) {
//        ImageUtils.loadImageFilterTransSkGray100(context, product.mainImg, binding.iv, null)
//        ImageUtils.loadImageFilterTrans(
//            context, product.mainImg, binding.iv, null, CommUtils.getColor(
//                com.starblink.basic.style.R.color.sk_gray0
//            ), itemW, itemW
//        )
        binding.iv.load(product.mainImg)
        binding.iv.click { //跳转商品外链
            product.id?.let { it1 ->
                product.merchantWeb?.let { it2 ->
                    CommonRoute.startProductDetail(
                        product.id!!,
                        product.standardSpuIds ?: "",
                        product
                    )
                }
            }
        }
        binding.iv.trackData(
            page = pageRef,
            element = SpmElementDef.GoodStoreBodyProductClick,
            traceInfo = product.traceInfo,
            params = SpmTrackHandler.trackProductMap(position, product),
            businessSuffixID = businessSuffixId(product)
        )
    }

}